﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;


public partial class MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        login log = new login();
        if (log.autenticarusuarios(txtuser.Text.ToString(), txtpws.Text.ToString()))
        {
            // se inicia la autentificacion 
            FormsAuthentication.Initialize();
            //se manda llamar la funcion para asignar los roles segun usuario
            string Roles = "" +log.Datos[1];
            FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1, txtuser.Text, DateTime.Now, DateTime.Now.AddMinutes(40), false, Roles, FormsAuthentication.FormsCookiePath);
            //version, UsuarioLogueado, Fecha del Logue, Tiempo de Vida de la session en minutos, si es persistente, Los roles del usuario, el path de las cockies
            //generar la cookie
            Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(fat)));
            Response.Redirect("Administrador/Default.aspx");
        }
    }
}
